//
//  LaunchViewController.m
//  Brand
//
//  Created by Lin Eidan on 14-5-31.
//  Copyright (c) 2014年 Faker. All rights reserved.
//

#import "LaunchViewController.h"
#import "AppDelegate.h"
#import "config.h"
#import "UIView+EidanSize.h"
#import <MediaPlayer/MediaPlayer.h>
#import "Header.h"

@interface LaunchViewController ()

@property (strong,nonatomic) MPMoviePlayerController *player;

@end

@implementation LaunchViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    NSString *mov = [[NSBundle mainBundle] pathForResource: (isiPhone5 ? @"launchImages" : @"launchImages4s") ofType:@"mov"];
    NSURL *url = [NSURL fileURLWithPath:mov];
    
    self.player = [[ MPMoviePlayerController alloc] initWithContentURL:url];
    self.player.view.frame = CGRectMake(0, 0, kScreen_Width, kScreen_Height);
    
    self.player.shouldAutoplay = YES;
    self.player.fullscreen = YES;
    self.player.movieSourceType = MPMovieSourceTypeFile;
    self.player.controlStyle = MPMovieControlStyleNone;
    self.player.fullscreen = YES;
    [self.view addSubview:self.player.view];
    self.player.view.backgroundColor = [UIColor clearColor];
    [self.player prepareToPlay];
    
    [self.player play];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(finishCallBack:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

    // Do any additional setup after loading the view.
}

-(void)viewWillAppear:(BOOL)animated{
   
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}

- (void) viewWillDisappear:(BOOL)animated{
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}

- (void)finishCallBack:(NSNotification *) notification{
    [self handleWhenGoBack];
}

-(void)handleWhenGoBack{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    [self.navigationController popViewControllerAnimated:NO];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL)prefersStatusBarHidden{
    return YES;
}

- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation{
    return UIStatusBarAnimationNone;
}

////控制状态栏方向
-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}



@end
